using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Summary description for ManagePerson
/// </summary>
public class ManagePerson
{
    public void newsletterSignup(Person per) 
    {
        enterNewPerson(per.FirstName, per.LastName, per.Address, per.City, per.State, per.Zip, per.PhoneNumber, per.Email, true, per.LibraryID);

    }
    public bool newsletterCancel(int PersonID) 
    {
        bool success = true;
        try
        {
            Person per = getPerson(PersonID);

            updatePerson(per);
        }
        catch (IndexOutOfRangeException)
        {
            success = false;
        }
       

        return success;
    }

    //Enter new person
    public void enterNewPerson(string firstName, string lastName, string address, string city,
                               string State, int zip, string phoneNumber, string email,
                               Boolean wantNewsLetter, int libraryId)
    {
        DatabaseAccess accessor = new DatabaseAccess();
        accessor.addPerson(firstName, lastName, address, city, State, zip, phoneNumber, email,
                           wantNewsLetter, libraryId);
    }

    //Enter new patron
    public void enterNewPatron(string firstName, string lastName, string address, string city, 
                               string State, int zip, string phoneNumber, string email,
                               Boolean wantNewsLetter, int libraryId, Boolean isAdult,
                               Boolean wantsNotifications, string PreferredContactMethod,
                               DateTime CardExpires, string Password) 
    {
        DatabaseAccess accessor = new DatabaseAccess();
        accessor.addPatron(firstName, lastName, address, city, State, zip, phoneNumber, email,
                           wantNewsLetter,libraryId,isAdult, wantsNotifications, PreferredContactMethod,
                           CardExpires, Password);
    }

    //Update Patron
    public void updatePatron(string firstName, string lastName, string address, string city,
                               string State, int zip, string phoneNumber, string email,
                               Boolean wantNewsLetter, int libraryId, Boolean isAdult,
                               Boolean wantsNotifications, string PreferredContactMethod,
                               DateTime CardExpires, string Password) 
    {
        DatabaseAccess accessor = new DatabaseAccess();
        accessor.UpdatePatron(firstName, lastName, address, city, State, zip, phoneNumber, email,
                           wantNewsLetter, libraryId, isAdult, wantsNotifications, PreferredContactMethod,
                           CardExpires, Password);
    }
    //Update Person
    public void updatePerson(Person per)
    {
        DatabaseAccess accessor = new DatabaseAccess();
        per.wantsNewsletter = false;
        accessor.UpdatePerson(per);
    }
    public void deletePerson(int PersonID) { }

    public Person getPerson(int personID)
    {
        DatabaseAccess da = new DatabaseAccess();
        return da.getPersonInfo(personID);
    }

    public SqlDataReader getAllPeople()
    {
        return null;
    }
    
    //Jacquie
    public DataSet findPerson(String searchString, int libraryId)
    {
        DatabaseAccess da = new DatabaseAccess();
        return da.findPerson_LibrarianView(searchString, libraryId);
    }

    //Jacquie
    public DataSet findPersonById(int PersonId, int libraryId)
    {
        DatabaseAccess da = new DatabaseAccess();
        return da.findPersonById_LibrarianView(PersonId, libraryId);
    }

    //Jacquie
    public DataSet getAllPeopleAtLibrary(int libraryId)
    {
        DatabaseAccess da = new DatabaseAccess();
        return da.getAllPeopleAtLibrary(libraryId);
    }
}
